package bdd.daos.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

import beans.*;

public class DAOOutils {
	private DBLink dblink;
	
	public DAOOutils(){
		this.dblink = new DBLink(); 
		this.dblink.connexion();
	}	

	public Integer findMaxId(String Table, String ChampDeLaTable) {
		Integer retour = 0;
		try {
			this.dblink.connexion();
			String r = "SELECT max("+ChampDeLaTable+") as ID FROM "+Table;
			this.dblink.setPst(this.dblink.getConnection().prepareStatement(r));
			ResultSet rs = this.dblink.getPst().executeQuery();
			while(rs.next()) {
				retour = rs.getInt("ID");
			}		
		}
		catch(SQLException se) {
			System.out.println("Erreur de requ�te" + se);
		}
		finally{
			this.dblink.deconnexion();
		}
		return retour;
	}
}
